package spring.cloud.tasks.executor.executor.task.execute_statistics;

import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.recipes.cache.TreeCacheEvent;
import spring.cloud.tasks.executor.executor.task.TreeCacheListener;

@Slf4j
@Setter
@Getter
class ExecuteStatisticsNeedReportListener extends TreeCacheListener {
    private final ExecuteStatisticsNeedReportListenerHolder taskExecuteInfoNeedReportListenerHolder;

    public ExecuteStatisticsNeedReportListener(ExecuteStatisticsNeedReportListenerHolder taskExecuteInfoNeedReportListenerHolder) {
        this.taskExecuteInfoNeedReportListenerHolder = taskExecuteInfoNeedReportListenerHolder;
    }

    @Override
    protected void dataChanged(CuratorFramework curatorFramework, String path, TreeCacheEvent treeCacheEvent) {
        if (taskExecuteInfoNeedReportListenerHolder.isShutdown) {
            return;
        }
        if (ExecuteStatisticsNeedReportNode.isReportPath(taskExecuteInfoNeedReportListenerHolder.taskId, path) && (TreeCacheEvent.Type.NODE_ADDED == treeCacheEvent.getType() || TreeCacheEvent.Type.NODE_UPDATED == treeCacheEvent.getType())) {
            log.info("接受到任务分片执行信息需要上传的指令", taskExecuteInfoNeedReportListenerHolder.taskId);
            //needReportListenerHolder.taskItemExecuteInfoService.report();
        }
    }
}
